package com.wxc.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author wxc
 * @date 2021年09月02日 11:13
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("响应格式")
public class Resp<T> implements Serializable {
    @ApiModelProperty("状态码")
    private int code;
    @ApiModelProperty("信息")
    private String message;
    @ApiModelProperty("数据")
    private T data;

    public static <T> Resp<T> success() {
        return new Resp<>(REnum.SUCCESS.getCode(), REnum.SUCCESS.getMessage(), null);
    }

    public static <T> Resp<T> success(T data) {
        return new Resp<>(REnum.SUCCESS.getCode(), REnum.SUCCESS.getMessage(), data);
    }

    public static <T> Resp<T> error(REnum RespEnum) {
        return new Resp<>(RespEnum.getCode(), RespEnum.getMessage(), null);
    }

    public static <T> Resp<T> error(REnum RespEnum, T data) {
        return new Resp<>(RespEnum.getCode(), RespEnum.getMessage(), data);
    }

    public static <T> Resp<T> error(int code, String message,T data) {
        return new Resp<>(code, message,data);
    }
}
